package com.robam.cloud.authcenter.helper.impl;

import com.robam.cloud.authcenter.helper.WechatAccessTokenGateway;
import com.robam.cloud.cache.annotation.CacheExpire;
import com.robam.cloud.common.bean.authcenter.entity.AuthPlatform;
import com.robam.cloud.common.util.wechat.WechatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

@Component
public class WechatAccessTokenOriginGateway extends WechatAccessTokenGateway {
    @Autowired
    WechatUtil wechatUtil;


    @Override
    @CacheExpire(expire = 3600)
    @Cacheable(value = "AUTH-CENTER", key = "'AccessToken_'+'appid_' + #authPlatform.getAppId()", unless = "#result == null")
    public String requestToken(AuthPlatform authPlatform) {
        return wechatUtil.getAccessToken(authPlatform.getAppId(), authPlatform.getAppSecret());
    }
}
